<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商品规格组合管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">规格基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品id：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id=productId class="form-control" value="${productId }"
                                                   readonly>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品寸尺规格：</label>
                                        <div class="col-lg-8" id="psizeListResult">
                                        	<select class="form-control" id="psizeId">
                                        		<c:forEach var="item" items="${psizeListResult}" varStatus="status">
						                             <option value="${item.id}">${item.name}</option>
						                    	</c:forEach>
						                    </select>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品颜色规格：</label>
                                        <div class="col-lg-8" id="pcListResult">
                                        	<select class="form-control" id="pcId">
                                        		<c:forEach var="item" items="${pcListResult}" varStatus="status">
						                             <option value="${item.id}">${item.name}</option>
						                    	</c:forEach>
						                    </select>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品款式规格：</label>
                                        <div class="col-lg-8" id="pstyleListResult">
                                        	<select class="form-control" id="pstyleId">
                                        		<c:forEach var="item" items="${pstyleListResult}" varStatus="status">
						                             <option value="${item.id}">${item.name}</option>
						                    	</c:forEach>
						                    </select>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品加工方式规格：</label>
                                        <div class="col-lg-8" id="ppmListResult">
                                        	<select class="form-control" id="ppmId">
                                        		<c:forEach var="item" items="${ppmListResult}" varStatus="status">
						                             <option value="${item.id}">${item.name}</option>
						                    	</c:forEach>
						                    </select>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                   <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品规格组合价格：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="basePrice" class="form-control"
                                                   placeholder="请输入商品规格组合价格">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                   </div>
                                   <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品规格状态：</label>
                                    	<div class="col-lg-8">
	                                        <select class="form-control" id="isActive">
		                                            <option value="0">未激活</option>
		                                            <option value="1">已激活</option>
	                                        </select>
                                    	</div>
                                    	<div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="product_create()"
                        style="margin-left:15px;margin-bottom:30px;">发布
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                  		  取消
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	var images = [],descs=[];
	var currentI = 0;
	
	function product_create() {
    	var baseURL = "${webPath}/product/createOfFormatPrice";
    	var productId = "${productId}";
        var name = $('#name').val();
        var psizeId = $("#psizeId").find("option:selected").val();
        var pcId = $("#pcId").find("option:selected").val();
        var pstyleId = $("#pstyleId").find("option:selected").val();
        var ppmId = $("#ppmId").find("option:selected").val();
        var basePrice = $('#basePrice').val();
		var isActive = $("#isActive").find("option:selected").val();

		var json_package = {
			"head" : {},
			"body" : {
				"productId" : productId,
				"productSizeId" : psizeId,
				"productColorId" : pcId,
				"productStyleId" : pstyleId,
				"productProcessingMethodsId" : ppmId,
				"basePrice" : basePrice,
				"isActive" : isActive
			}
		};
		$.post(baseURL, {
			"json_package" : JSON.stringify(json_package)
		}, function(result) {
			if (typeof result == 'string')
				result = JSON.parse(result);
			if (result.body.result == '0') {
				alert(result.body.description)
				window.location.href = "${webPath}toProductFormatPriceList/"
						+ productId;
			} else {
				alert(result.body.description)
			}
		})
	}

	$(function() {
		$('#cancel').click(function() {
			window.location.href = "${webPath}toProductFormatPriceList/${productId}";
		})
	});
	
	$(document).ready(function(e) {
		$('#pro_info').keydown(function() {
			var len = $(this).val().length;
			if (len >= 100) {
				var num = $(this).val().substring(0, 99);
				$(this).val(num);
				alert("超过字数限制")
			}
		})
	});
	$(document).ready(function(e) {
		$('#pro_desc').keydown(function() {
			var len = $(this).val().length;
			if (len >= 140) {
				var num = $(this).val().substring(0, 139);
				$(this).val(num);
				alert("超过字数限制")
			}
		})
	});
</script>
</body>
</html>